/*
 * Gaetan Gautier, Stanislas Kobak, Nicolas Kobak
 */

package scheduling.algorithm.order;


import java.util.Comparator;

import scheduling.schedule.TaskInstance;
import task.PeriodicTask;


public class RateMonotonicOrder implements Comparator<TaskInstance>
{
	@Override
	public int compare(TaskInstance event1, TaskInstance event2) 
	{
		int compare = 0;
		
		if(((PeriodicTask) event1.getFakeTask()).getPeriod() != ((PeriodicTask) event2.getFakeTask()).getPeriod() )
		{
			compare = ((PeriodicTask) event1.getFakeTask()).getPeriod() > ((PeriodicTask) event2.getFakeTask()).getPeriod() ? 1 : -1;
		}
		else if(event1.getFakeTask().getId() != event2.getFakeTask().getId())
		{
			compare = event1.getFakeTask().getId() > event2.getFakeTask().getId() ? 1 : -1;
		}
		else if(event1.getEarliestDate() != event2.getEarliestDate())
		{
			compare = event1.getEarliestDate() > event2.getEarliestDate() ? 1 : -1;
		}
		
		return compare;
	}
}
